#=00 the with statement
#=01 enable 'with' (default in 2.6)
from __future__ import with_statement #01

#=02 files
with open('/etc/passwd') as fp:     #02
    for line in fp:                 #02
        print line.strip()          #02
# the file is closed at this point  #02

#=03 threading.Lock
lock = threading.Lock()  #03
...                      #03
with lock:               #03
    doCriticalCode()     #03
# lock is released       #03
    
#=04 your own transaction object
#=05 calls transobj.__enter__()
#=06 do some stuff
with transaction():     #05
    doStuff()     #06
    doOtherStuff()     #06
#=07 calls transobj.__exit__() 
